package com.agileplex.codeminer.commons;

import java.util.HashMap;
import java.util.Map;

/**
 * It's a helper class for Map<key, Map<k, v>> structure
 * 
 * @creator Weiming Yin
 * @date 2007-6-5
 *
 * @lastmodified
 * @author $Author: yinweiming $
 * @version $Version$, $Date: 2007-06-05 16:38:16 +0000 (Tue, 05 Jun 2007) $
 */
public class MapContainer<T, K, V> {
	private Map<T, Map<K, V>> map;
	
	public MapContainer() {
		this.map = new HashMap<T, Map<K, V>>();
	}
	
	public V get(T t, K k) {
		Map<K, V> m = map.get(t);
		if (m == null) {
			return null;
		}
		
		return m.get(k);
	}
	
	public V set(T t, K k, V v) {
		Map<K, V> m = map.get(t);
		synchronized (t) {
			if (m == null) {
				m = new HashMap<K, V>();
				map.put(t, m);
			}
		}
		
		return m.put(k, v);
	}
	
	
	
}
